<<<<<<< HEAD
﻿using System;
using System.IO;
using System.Text.RegularExpressions;
using MySql.Data.MySqlClient;
using System.Collections;
using System.Threading;

namespace UDPSocketProject
{
    public class MacOuiManager
    {
        public MacOuiManager()
        {
        }

        public static void InsertOui(){
            Console.WriteLine("开始存储Oui数据....");
            StreamReader streamReader = File.OpenText(@"oui.txt"); 
            string nextLine;
            int macCount = 0;
            Queue matchQueue = new Queue();
            while ((nextLine = streamReader.ReadLine()) != null) 
            {
                Array spiltArray = nextLine.Split(' ');
                foreach (string str in spiltArray)
                {
                    MatchCollection maths = Regex.Matches(str, @"\w{2}[-]\w{2}[-]\w{2}");
                    foreach (Match match in maths)
                    {
                        if(!matchQueue.Contains(match.ToString()))
                        {
                            matchQueue.Enqueue(match.ToString());
                            macCount++;
                        }
                    }
                }
            } 
            Console.WriteLine("有{0}条mac数据需要写入数据库.", macCount);

            int insertedCount = 0;
            Queue taskQueue = new Queue();
            foreach (string match in matchQueue)
            {
                if (InsertSql(match))
                {
                    Console.Write(".");
                    //Thread.Sleep(50);
                    insertedCount++;
                }
            }

            Console.WriteLine("存储Oui数据完成,共写入数据 {0} 条",insertedCount);
            streamReader.Close(); 
        }

        public static bool InsertSql(string mac)
        {
            string macBase16 = mac.Replace("-", "");
            SqlHelper sqlHelper = new SqlHelper();
            bool exists = sqlHelper.existsData("select 1 from MacOui WHERE MacHex = '" + mac + "';");
            if (!exists)    //检查要插入的数据是否存在，存在则放弃数据写入
            {
                sqlHelper.executMysqlcom("INSERT INTO MacOui (MacHex,MacBase16) VALUES('" + mac + "','" + macBase16 + "');");
                return true;
            }
            return false;
        }
    }
}
=======
﻿using System;
using System.IO;
using System.Text.RegularExpressions;
using MySql.Data.MySqlClient;
using System.Collections;
//using System.Threading.Tasks;
using System.Threading;

namespace UDPSocketProject
{
    public class MacOuiManager
    {
        public MacOuiManager()
        {
        }

        public static void InsertOui(){
            Console.WriteLine("开始存储Oui数据....");
            StreamReader streamReader = File.OpenText(@"oui.txt"); 
            string nextLine;
            int macCount = 0;
            Queue matchQueue = new Queue();
            while ((nextLine = streamReader.ReadLine()) != null) 
            {
                Array spiltArray = nextLine.Split(' ');
                foreach (string str in spiltArray)
                {
                    MatchCollection maths = Regex.Matches(str, @"\w{2}[-]\w{2}[-]\w{2}");
                    foreach (Match match in maths)
                    {
                        if(!matchQueue.Contains(match.ToString()))
                        {
                            matchQueue.Enqueue(match.ToString());
                            macCount++;
                        }
                    }
                }
            } 
            Console.WriteLine("有{0}条mac数据需要写入数据库.", macCount);

            int insertedCount = 0;
            Queue taskQueue = new Queue();
            foreach (string match in matchQueue)
            {
                if (InsertSql(match))
                {
                    insertedCount++;
                }
            }

            Console.WriteLine("存储Oui数据完成,共写入数据 {0} 条",insertedCount);
            streamReader.Close(); 
        }

        public static bool InsertSql(string mac)
        {
            string macBase16 = mac.Replace("-", "");
            SqlHelper sqlHelper = new SqlHelper();
            MySqlDataReader dataReader = sqlHelper.getmysqlread("select 1 from MacOui WHERE MacHex = '" + mac + "';");
            if (!dataReader.HasRows)    //检查要插入的数据是否存在，存在则放弃数据写入
            {
                sqlHelper.executMysqlcom("INSERT INTO MacOui (MacHex,MacBase16) VALUES('" + mac + "','" + macBase16 + "');");
                return true;
            }
            return false;
        }
    }
}
>>>>>>> 52a137e... * System.Data.SqlClient.dll: 添加并发处理类
